<?php 

class specification  {




	public function insert($parm){
		 DB::insert("sysSpecification",array('productId','model1','model2','model3','status'))
					 ->values(array($parm['productId'],$parm['model1'],$parm['model2'],$parm['model3'],$parm['status']))
					 ->execute();
	}
	 	
	 public function delete($parm){

   		DB::delete('sysSpecification')->where('productId','=',$parm['id'])->execute();
	}
	public function get($parm){
		$result = DB::select('*,sysSpecification.id as showid')->from('sysSpecification')->join("sysproductexpresssku",'left')->on("sysSpecification.id","=","sysproductexpresssku.specificationId")->where("sysSpecification.id","=",$parm['id'])->execute()->as_array();
		return $result;
	}

	public function getByIdlist($parm){
		$query = DB::query(Database::SELECT,
			'select * from sysSpecification  where  id in('.join(",",$parm['id']).') ')->execute()->as_array();
		return $query;

	}
	public function getByModel($parm){
		$result = DB::select('*')->from('sysSpecification')->where("productId","=",$parm['productId'])->execute()->as_array();

		foreach($result as $key =>$value){
			if(!isset($parm['model2']) ||$parm['model2'] =="" ){
				if($parm['model1'] == $value['model1']){
					return $value['id'];
				}
			}else if(!isset($parm['model3']) ||$parm['model3'] =="" ){
				if(($parm['model1'] == $value['model1']&&$parm['model2'] == $value['model2'])
				||($parm['model1'] == $value['model2']&&$parm['model2'] == $value['model1'])){
					return $value['id'];
				}
			}else{
				$liststr = array();

				$liststr1 = array();
				array_push($liststr1,$parm['model1']);
				array_push($liststr1,$parm['model2']);
				array_push($liststr1,$parm['model3']);

				array_push($liststr,$value['model1']);
				array_push($liststr,$value['model2']);
				array_push($liststr,$value['model3']);
				usort($liststr1,"strcmp");
				usort($liststr,"strcmp");
				if(implode(',',$liststr)==implode(',',$liststr1)){
					return $value['id'];
				}
			}

		}

	}




}